<!DOCTYPE html>
<style>
#box {
  width: 100px;
  height: 100px;
  background-color: #00ff00;
}

#covered {
  width: 100px;
  height: 100px;
  background-color: #ff8080;
}

/* The scroller is not originally scrollable. */
.scroller {
  overflow: visible;
  height: 100px;
  width: 100px;
}

.overflow {
  overflow-y: scroll;
  will-change: transform; /* force compositing */
}

#contents {
  height: 1000px;
}
</style>

<div id="box"></div>
<div id="covered"></div>
<div id="scroller" class="scroller">
  <div id="contents"></div>
</div>

<script id="passthrough_animator"  type="text/worklet">
registerAnimator("passthrough_animator", class {
  animate(currentTime, effect) {
    effect.localTime = currentTime;
  }
});
</script>

<script src="resources/animation-worklet-tests.js"></script>
<script>
if (window.testRunner) {
  testRunner.waitUntilDone();
}

runInAnimationWorklet(
  document.getElementById('passthrough_animator').textContent
).then(()=>{
  const box = document.getElementById('box');
  const effect = new KeyframeEffect(box,
    [
     { transform: 'translateY(0)' },
     { transform: 'translateY(200px)' }
    ], {
      duration: 1000,
    }
  );

  const scroller = document.getElementById('scroller');
  const timeline = new ScrollTimeline({ scrollSource: scroller, orientation: 'block' });
  const animation = new WorkletAnimation('passthrough_animator', effect, timeline);
  animation.play();

  // Ensure that the WorkletAnimation will have been started on the compositor.
  waitTwoAnimationFrames(function() {
    // Now make the scroller overflow, which will cause it to be composited and
    // the animation should update on the compositor side.
    scroller.classList.add('overflow');
    const maxScroll = scroller.scrollHeight - scroller.clientHeight;
    scroller.scrollTop = 0.5 * maxScroll;

    if (window.testRunner) {
      waitForAnimationFrames(3, _ => {
        testRunner.notifyDone();
      });
    }
  });
});
</script>
